import { Module } from 'vuex'
import RootStateTypes from '../../interface'
import ThemeStateType from './interface'

const theme: Module<ThemeStateType, RootStateTypes> = {
    namespaced: true,
    state: (): ThemeStateType => ({
        dark: (localStorage.getItem('App.Theme.Dark') || '') == 'true',
        collaps: (localStorage.getItem('App.Theme.Collaps') || '') == 'true',
    }),
    mutations: {
        setDark(state, flag: boolean) {
            state.dark = flag
            localStorage.setItem('App.Theme.Dark', String(flag))
        },
        setCollaps(state, flag: boolean) {
            state.collaps = flag
            localStorage.setItem('App.Theme.Collaps', String(flag))
        },
    },
}

export default theme
